<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <style>
        .ui-jqgrid tr.jqgrow td {
            white-space: normal !important;
            height: 35px;
            vertical-align: text-top;
            padding-top: 2px;
        }

        .span_css {
            font-size: 16px;
            font-weight: 700;
        }

    </style>
</head>
<body class="no-skin">

<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>

<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <div class="pull-left">
                            <button class="btn btn-sm btn-info downloadFile" data-id="r8bEf9MxoeUbWZpX" id="downloadTemplate">
                                下载主要经济指标模板
                            </button>
                            <input class="btn btn-sm btn-default" style="display:inline;" type="file" name="file"
                                   id="file" accept=".xlsx">
                            <button class="btn btn-sm btn-success upload" id="importIndicatorBreakdown"
                                    data-id="import">导入主要经济指标
                            </button>
                            <span class="span_css">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;目前库内的数据时间:</span>
                            <div style="float:right; margin-left: 10px;">
                                <select name="date" id="date" class="form-control">

                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div><!-- /.main-container -->
</div>

<%--公用js--%>
<script src="<s:url value="/assets/web/js/commo.js"></s:url>"></script>

<!-- footer -->
<%@ include file="/WEB-INF/views/include/footer.jsp" %>

<script src="<s:url value="/assets/js/ajaxfileupload.js"></s:url>"></script>
<script>
    $(function () {
        //查询数据内主要经济指标的时间点
        $.ajax({
            type: "GET",
            url: "/communal/queryIndicatorAllDateTimes",
            dataType: "json",
            data: {},
            success: function (indicators) {
                if (indicators.length > 0) {
                    var html = "<option value=\"\">--点击查看--</option>";
                    for (var i = 0; i < indicators.length; i++) {
                        html = html + "<option value=" + indicators[i] + ">" + indicators[i] + "</option>"
                    }
                    $("#date").html(html);
                }
            },
            error: function (model) {
            }
        });


        /**
         * 下载模板
         */
        $(".downloadFile").click(function () {
            var id = $(this).data("id");
            var url = "/communal/download/" + id;
            window.open(url);
        });

        //    上传
        $(".upload").click(function () {
            debugger;
            var fileval = $(this).prev().val();
            console.log(fileval);
            var fileId = $(this).prev().attr("id");
            console.log(fileId);
            if (fileval == null || fileval == "") {
                alert("未选择任何文件");
                return;
            }

            $("#dialog").show();
            $.ajaxFileUpload({
                type: "post",
                fileElementId: fileId,
                secureuri: false,
                dataType: 'json',
                url: "/communal/importIndicatorBreakdown",
                async: true,
                success: function (data) {
                    if (data.code == "200") {
                        alert("数据导入成功");
                        window.location.href = '/dataImport';
                    } else if(data.code == "500"){
                        alert(data.data);
                    } else{
                        alert("数据导入成功 ！！请联系管理员");
                    }
                }
            });

        });
    })
</script>
</body>
</html>